package qj.tool.http;

import java.net.*;
import java.io.*;

public class URLReader {
    public static void main(String[] args) throws Exception {
        
        Authenticator auth = new Authenticator() {

            protected PasswordAuthentication getPasswordAuthentication() {
                if ("192.168.108.8".equals(this.getRequestingHost()))
                    return new PasswordAuthentication("tuna", "tuna789".toCharArray());
                else
                    return new PasswordAuthentication("tuna", "tuna789".toCharArray());
            }
        };
        Authenticator.setDefault(auth);

        // Configure proxy ...
        System.setProperty("http.proxySet", "true");
        System.setProperty("http.proxyHost", "192.168.108.8");
        System.setProperty("http.proxyPort", "3128");
        System.setProperty("http.proxyType", "4");

        long c1 = System.currentTimeMillis();
        // Open URL ...
        URL url = new URL("http://www.google.com/");
        BufferedReader in = new BufferedReader (
                              new InputStreamReader (
                                url.openConnection().getInputStream()
                                //url.openStream()
                              )
                            );
        long c2 = System.currentTimeMillis();
        // Read it ...
        String inputLine;
        while ((inputLine = in.readLine()) != null)
          System.out.println(inputLine);

        in.close();
    }
}